/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-06-29 09:48:04
 * @LastEditTime : 2023-07-06 16:53:25
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\FirstLevel\BuildList.jsx
 * @Description  :
 */
import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton } from '../Common/options'
import { BuildListTree } from '../Common/Conversion'

export const BuildList = async ({ url, OptionsEvent, Permission }) => {
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        hideInSearch: true,
        get: API_LIST()[`get${url}Tree`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission.findIndex(v => v.uuid === 'b6cab3da-3469-4ae8-b2e6-b9b1a0990019') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.tableName, rules: true, width: 400 },
            { ...commonTableList.code, rules: true },
            {
                ...commonTableList.parentUuid,
                fieldProps: {
                    fieldNames: { label: 'tableName', value: 'uuid' },
                    options: await BuildListTree(),
                },
            },
            { ...commonTableList.sortId, rules: true },
            {
                dataIndex: 'isImportant',
                title: '重要节点',
                valueType: 'select',
                valueEnum: BuiltInData.isYes,
                rules: true,
                width: 150,
            },
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 150,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { children } = record
                    return [
                        Permission.findIndex(v => v.uuid === '35bd4418-41d2-4ca5-a6ea-3db322d7f922') !== -1 && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        Permission.findIndex(v => v.uuid === 'b90b47aa-d9ab-44b1-979d-faa3d973cdf1') !== -1 &&
                            !children && (
                                <DelDataButton
                                    OptionsEvent={OptionsEvent}
                                    key="del"
                                    title="删除"
                                    url={url}
                                    uuid={record.uuid}
                                />
                            ),
                    ]
                },
            },
        ],
    }
    return data
}
